package com.hp.attendance.serlvet.position;
import com.hp.attendance.entity.Position;
import com.hp.attendance.service.PositionService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
@WebServlet("/updateposition")
public class PositionUpdateServlet extends HttpServlet {
    private PositionService positionService =new PositionService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //修改
        try {
            String id = req.getParameter("id");
            String position_number = req.getParameter("position_number");
            String name = req.getParameter("name");
            String level = req.getParameter("level");
            String notes = req.getParameter("notes");

            Position position = new Position(Integer.parseInt(id),Integer.parseInt(position_number), name, level ,notes);
            positionService.updatePosition(position);


            //跳转到list列表
            req.getRequestDispatcher("/PagePosition").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
